#include <iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int today_price = 0, yesterday_price = 0x3f3f3f;
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> today_price;
        if (today_price > yesterday_price)
            ans += today_price - yesterday_price;
        yesterday_price = today_price;
    }
    cout << ans << endl;
    return 0;
}